<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
    .errorText
    {
        color:red;
    }
    </style>
</head>

<body>
	<form id="form1" method="post">
        <div style="padding-left:30px;padding-bottom:10px;">
            <table style="table-layout:fixed;" cellspacing="0" cellpadding="5">
            	<tr>
            		<td style="width:100px;">用户名：</td>
                    <td style="width:100px;">    
                        <input name="name" errorMode="none"  onvalidation="checkValidation" requiredErrorText="用户名不能为空"  class="mini-textbox" required="true" vtype="maxLength:50" style="width: 130px" />
                    </td>
                 	<td id="name_error" class="errorText" ></td>
            	</tr>
            	<tr>
            		<td style="width:20px;">登录名：</td>
                    <td style="width:100px;">    
                        <input name="username"  class="mini-textbox" readOnly="true" vtype="maxLength:30" style="width: 130px"/>
                    </td>
                </tr>
                <tr>
                    <td style="width:20px;">密码：</td>
                    <td style="width:100px;">    
                        <input name="password" errorMode="none" onvalidation="checkValidation"  class="mini-password" vtype="maxLength:15" style="width: 130px"/>
                    </td>
                    <td id="password_error" class="errorText" ></td>
                </tr>
				<tr>
               		<td style="width:20px;">部门：</td>
                    <td>
						<input id="combo1" name="deptType" class="mini-combobox" style="width:150px;" textField="keyValue" valueField="keyName" emptyText="请选择..."
				        		url="dictionary_key_val_view.do?typeName=DEPT_TYPE" onValueChanged="changeValue" required="true" allowInput="false" showNullItem="true" nullItemText="请选择..."/> 
                    </td>  
                </tr>
                <tr id="blongs_group" style="display:none;">
                	<td style="width:20px;">所属组：</td>
                	<td>
						<input id="combo2" name="groupId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
    						url="user_group_view.do" popupWidth="150px;" popupHeight="120px;" allowInput="false" showNullItem="true" required="true" nullItemText="请选择..."/>
                    </td>
                </tr>
                <tr id="leader_group" style="display:none;">
                	<td style="width:20px;">是否组长：</td>
                	<td>
						<input id="is_leader" class="mini-radiobuttonlist" name="isLeader" required="true" data=[{id:"1",text:"组长"},{id:"2",text:"组员"}] />
                    </td>
                </tr>
                <tr>
                	<td style="width:20px;">角色：</td>
                    <td>
							<div id="combo3" class="mini-combobox" style="width:150px;" name="roleId" popupWidth="165" textField="name" valueField="id" 
							    url="user_role_view.do" multiSelect="true" required="true" showClose="true" oncloseclick="onCloseClick" >     
							    <div property="columns">
							        <div header="角色(精确)" field="name"></div>
							    </div>
							</div>
                    </td>
                </tr>
                <tr>
                	<td style="width:20px;">状态：</td>
                    <td>
                    	<input id="combo4" name="jobStatus" class="mini-combobox" style="width:150px;" textField="keyValue" valueField="keyName" emptyText="请选择..."
				        		url="dictionary_key_val_view.do?typeName=JOB_STATUS" required="true" allowInput="false" showNullItem="true" nullItemText="请选择..."/>
                    </td>
                </tr>
                <tr>
                    <td style="width:20px;">联系电话：</td>
                    <td style="width:100px;">    
                        <input name="mobile" errorMode="none" onvalidation="checkValidation"  class="mini-textbox" vtype="maxLength:15" style="width: 130px"/>
                    </td>
                    <td id="mobile_error" class="errorText" ></td>
                </tr>
                <tr>
                    <td style="width:20px;">备注：</td>
                    <td colspan="3">    
                        <input name="description" class="mini-textarea" vtype="maxLength:255" style="width:200px;" />
                    </td>
                </tr>
            </table>
            <input id="text1"  name="id" class="mini-hidden" />
        </div>
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:50px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>
</body>

<script type="text/javascript">
	mini.parse();
	var form = new mini.Form("form1");
	
	function SaveData() {
        var o = form.getData(true);            
		
        form.validate();
        if (form.isValid() == false) return;
        $.ajax({
            url: "medical_useredit_save.do",
			type: 'post',
			dataType: 'json',
            data: o,
            cache: false,
            success: function (text) {
            	if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else {
	            	mini.alert("数据错误");
	            }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
                CloseWindow();
            }
        });
    }
	
	function onOk(e) {
        SaveData();
    }
	
	function SetData(data){
	     data = mini.clone(data);
	     if('cm' == data.row.deptType || 'om' == data.row.deptType) {
	    	 $("#blongs_group").show();
	    	 $("#leader_group").show();
	     }
	     form.setData(data.row);
	}
	
	function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
	
	function onCancel(e) {
        CloseWindow("cancel");
    }

   	function updateError(e) {
	    var id =e.sender.name + "_error";
	    var el = document.getElementById(id);
	    if (el) {
	        el.innerHTML =e.errorText;
	    }
   	}
   
   	function checkValidation(e) {                  
  		updateError(e);
   	}
	
   	function changeValue() {
   		var dept = mini.get("combo1").getValue();
   		if(dept == 'cm' || dept == 'om') {
   			$("#blongs_group").show();
   			$("#leader_group").show();
   		} else {
   			$("#blongs_group").hide();
   			$("#leader_group").hide();
   		}
   		mini.get("is_leader").setValue(null);
		mini.get("combo2").setValue(null);
   	}
    
    function onCloseClick(e) {
        var obj = e.sender;
        obj.setText("");
        obj.setValue("");
    }
</script>